$(function () {
  //粒子线条背景
  $(document).ready(function () {
    $(".layui-container").particleground({
      dotColor: "#7ec7fd",
      lineColor: "#7ec7fd",
    });
  });
  //登录
  $("form").on("submit", function (e) {
    e.preventDefault();
    //获取表单值
    let data = $(this).serialize();
    console.log(data);
    $.ajax({
      type: "post",
      url: "/api/login",
      data,
      success: (res) => {
        console.log(res);
        //判断是否登陆成功
        if (res.status === 0) {
          //登陆成功
          //提示
          layer.msg(
            res.message,
            {
              time: 1000, //1秒关闭（如果不配置，默认是3秒）
            },
            function () {
              //在localStorage中添加token
              localStorage.setItem("token", res.token);
              location.href = "./index.html";
            }
          );
        } else {
          layer.msg(res.message);
        }
      },
    });
  });
})();
